<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>赛事列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/iconfont.css">
    <link rel="stylesheet" href="../lib/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <script src="../js/base.js"></script>
    <script src="../js/area.js"></script>
    <style>
        tr td,
        tr th {
            text-align: center !important;
            border: none !important;
        }

        .layui-laydate-content tr td {
            border-bottom: none !important;
            border-top: none !important;
        }

        tr td {
            border-bottom: 1px solid #eee !important;
            border-top: 1px solid #eee !important;
        }

        .layui-form-select {
            width: 100px;
            float: left;
            display: inline-block;
            vertical-align: middle;
        }

        .layui-show-xs-block input {
            border: 1px solid #e6e6e6;
            border-radius: 4px;
            height: 30px;
            line-height: 30px;
            padding-left: 6px;
        }

        .layui-show-xs-block label {
            float: left;
            display: block;
            width: 66px;
            line-height: 32px;
            text-align: right;
            margin-right: 10px;
        }

        .search {
            margin-left: 20px;
        }

        .laytable-cell-1-0-12 {
            text-align: left;
        }
    </style>
</head>

<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card" style="display: flex;justify-content: space-between;">
                    <div class="layui-card-body ">
                        <blockquote class="layui-elem-quote" style="border:0;font-size: 18px;color: #000;">赛事列表
                        </blockquote>
                    </div>
                </div>
            </div>
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-fluid">
                        <div class="layui-row layui-col-space15">
                            <div class="layui-col-md12">
                                <div class="layui-card-body " style="display: flex;justify-content:space-between">
                                    <form class="layui-form" action="">
                                        <div class="layui-inline layui-show-xs-block">
                                            <label>赛事名称</label>
                                            <input type="text" id="name" name="name">
                                        </div>
                                        <div class="layui-inline layui-show-xs-block">
                                            <label>举办地</label>
                                            <select id="s_province" name="city" lay-filter="s_province">
                                            </select>
                                        </div>
                                        <div class="layui-inline layui-show-xs-block">
                                            <select id="s_city" name="city">
                                            </select>
                                        </div>
                                        <div class="layui-inline layui-show-xs-block">
                                            <label>开始时间</label>
                                            <input type="text" id="date" name="date">
                                        </div>
                                        <div class="layui-inline layui-show-xs-block">
                                            <label>赛事数据</label>
                                            <select id="type" name="type">
                                                <option value="">全部</option>
                                                <option value="1">已完善</option>
                                                <option value="0">数据待完善</option>
                                            </select>
                                        </div>
                                        <!-- <div class="layui-inline layui-show-xs-block">
                                            <label>发布状态</label>
                                            <select id="issueStatus" name="issueStatus">
                                                <option value="">全部</option>
                                                <option value="1">已发布</option>
                                                <option value="2">草稿箱</option>
                                            </select>
                                        </div> -->
                                        <div class="layui-inline layui-show-xs-block">
                                            <button class="layui-btn search" data-type="reload" lay-filter="add">查询
                                            </button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-card-body layui-table-body layui-table-main">
                <!-- 表格部分开始 -->
                <table id="video_table" lay-filter="test" lay-data="{id: 'testReload'}"></table>
                <script type="text/html" id="barDemo">
                    <a lay-event="watch" class="btn_a layui-btn layui-btn-xs">查看</a>
                    <!-- {{#  if(d.status!=1&&d.issueStatus==1){}}
                    <a lay-event="approval" class="btn_a layui-btn layui-btn-xs">审核</a>
                    {{#  } }}
                    <a lay-event="del" class="btn_a layui-btn layui-btn-danger layui-btn-xs">删除</a> -->
                </script>

                <script type="text/html" id="barDemo2">
                    {{#  if(d.issueStatus==1){ }}
                    <a lay-event="edit" class="btn_a layui-btn layui-btn-xs ">编辑</a>
                    {{#  } }}
                    {{#  if(d.issueStatus!=1){ }}
                    -
                    {{#  } }}
                </script>
                <script type="text/html" id="barDemo3">
                    {{#  if(d.issueStatus==1){ }}
                    <a lay-event="edit2" class="btn_a layui-btn layui-btn-xs ">编辑</a>
                    {{#  } }}
                    {{#  if(d.issueStatus!=1){ }}
                    -
                    {{#  } }}
                </script>
                <script type="text/html" id="barDemo4">
                    {{#  if(d.competitionData==0){ }}
                    <a lay-event="perfect" class="btn_a layui-btn layui-btn-xs">未完善</a>
                    {{#  } else { }}
                    已完善
                    {{#  } }}
                </script>
                <script type="text/html" id="barDemo5">
                    {{d.province}}{{d.city}}
                </script>
                <script type="text/html" id="barDemo6">
                    {{#  if(d.issueStatus==2){ }}
                    <a lay-event="changeSaishi" class="btn_a layui-btn layui-btn-xs">编辑</a>
                    {{#  } }}
                    {{#  if(d.issueStatus!=2){ }}
                    -
                    {{#  } }}
                </script>
                <!-- 表格结束 -->
            </div>
        </div>
    </div>
    </div>
</body>

</html>
<script>
    _init_area()
    layui.use(['table', 'form', 'laydate'], function () {
        var table = layui.table;
        var laydate = layui.laydate;
        var form = layui.form;
        var index = layer.load(1); //添加laoding,0-2两种方式
        laydate.render({
            elem: '#date',
            type: 'month'
        });
        // 监听select改变，省市联动
        form.on('select(s_province)', function (data) {
            change(1);
            form.render('select');
        });
        //第一个实例
        var ins1 = table.render({
            elem: '#video_table', //指定原始表格元素选择器（推荐id选择器）
            // height: 600,
            width: "100%",
            where: {
                status: "1",
                identity:"1"
            },
            // 附加参数，post token
            loading: true,
            method: 'get',
            url: findAllNewCompetitionList, //数据接口
            page: true, //开启分页
            // toolbar: 'default', //开启工具栏，此处显示默认图标
            cols: [
                [ //表头
                    // { type: 'checkbox', fixed: 'left' },
                    {
                        field: 'id',
                        title: 'ID',
                        width: 150
                    },
                    {
                        field: 'name',
                        title: '赛事名称',
                        width: 150
                    },
                    {
                        field: 'organizers',
                        title: '主办方',
                        width: 150
                    },
                    {
                        field: 'city',
                        title: '举办地',
                        width: 150,
                        templet: '#barDemo5'
                    },
                    {
                        field: 'competitionStartTime',
                        title: '开始时间',
                        width: 150
                    },
                    // {
                    //     field: 'organizers',
                    //     title: '赛程安排',
                    //     width: 150,
                    //     toolbar: '#barDemo3'
                    // },
                    // {
                    //     field: 'contractor',
                    //     title: '裁判安排',
                    //     width: 150,
                    //     toolbar: '#barDemo2'
                    // },
                    {
                        field: 'issueStatus',
                        title: '发布状态',
                        width: 150,
                        templet: function (d) {
                            if (d.issueStatus == "1") {
                                return "已发布"
                            } else if (d.issueStatus == "2") {
                                return "草稿箱"
                            }
                        }
                    },
                    // {
                    //     field: 'issueStatus',
                    //     title: '基本信息修改',
                    //     width: 150,
                    //     templet: "#barDemo6"
                    // },
                    {
                        field: 'applyTime',
                        title: '申请提交时间',
                        width: 150
                    },
                    {
                        field: 'competitionData',
                        title: '赛事数据',
                        width: 150,
                        templet: "#barDemo4"
                        // toolbar: '#barDemo4'
                    },
                    {
                        field: 'status',
                        title: '审批状态',
                        width: 150,
                        templet: function (d) {
                            if (d.status == "0") {
                                return "待审批"
                            } else if (d.status == "1") {
                                return "审批通过"
                            } else if (d.status == "2") {
                                return "已驳回"
                            } else {
                                return ""
                            }
                        }
                    },
                    {
                        fixed: 'right',
                        title: "操作",
                        width: 250,
                        align: 'center',
                        toolbar: '#barDemo'
                    }
                ]
            ],
            id: 'testReload',
            done: function (res) {
                console.log(res)
                if (res.msg == "2") {
                    parent.window.location.href = getRequestPrefix() + "/footBallAdmin/login.html"
                }
                layer.close(index)
            }
        });
        //给查询添加点击事件
        $('.search').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
            //一定要阻止表单的默认行为（刷新）
            return false
        });
        //头部输入框筛选功能
        active = {
            reload: function () {
                var name = $('#name');
                var type = $('#type');
                var province = $('#s_province');
                var city = $('#s_city');
                var date = $('#date');

                // var issueStatus = $('#issueStatus');
                // 执行重载（重新加载数据表格）
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    where: {
                        "name": name.val(),
                        "type": type.val(),
                        "province": province.val(),
                        "city": city.val(),
                        "date": date.val(),
                        // "issueStatus": issueStatus.val(),
                    }
                }, 'data');
            }
        };
        //监听头工具栏事件
        //监听点击的按钮，获取行信息
        table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            //获得当前行数据
            var $ = layui.$
            var data = obj.data,
                layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === "del") {
                layer.confirm('确定删除么', function (index) { //点击确定后，才执行下面语句
                    $.ajax({
                        type: "get",
                        url: delCompetition_del,
                        data: {
                            competitionId: data.id
                        },
                        success: function (res) {
                            console.log(res)
                            // return
                            if (res.code == 200) {
                                layer.alert(res.msg, {
                                    title: '提示',
                                    end: function () {
                                        location
                                            .reload(); //弹出层结束后，刷新主页面
                                    }
                                })
                            } else if (res.code != 200) {
                                layer.alert(res.msg, {
                                    title: '提示'
                                })
                            }
                        }
                    })
                    //向服务端发送删除指令
                });
            }
            //点击查看
            if (layEvent === "watch") {
                // layer.msg('审批');
                layer.open({
                    content: "match_info.html",
                    type: 2,
                    area: ["100%", "100%"],
                    title: "查看信息",
                    shadeClose: true,
                    success: function (layero, index) {
                        //获取点击行的数据,获取打开的iframe
                        // console.log(data)
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        body.find('.title').attr("data-val", data.id)
                    }
                })
            };
            // 点击未完善
            if (layEvent === "perfect") {
                // layer.msg('审批');
                layer.open({
                    content: "event_data.html",
                    type: 2,
                    area: ["100%", "100%"],
                    title: "赛事数据",
                    shadeClose: true,
                    success: function (layero, index) {
                        //获取点击行的数据,获取打开的iframe
                        console.log(data)
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        iframeWin.child(data.id)
                    }
                })
            };
            if (layEvent === "changeSaishi") {
                // layer.msg('审批');
                // 基本信息修改
                layer.open({
                    content: "newMatch_judge.html",
                    type: 2,
                    area: ["100%", "100%"],
                    title: "修改基本信息",
                    shadeClose: true,
                    success: function (layero, index) {
                        //获取点击行的数据,获取打开的iframe
                        console.log(data)
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        iframeWin.child(data.id)
                    }
                })
            };
            if (layEvent === "edit2") {
                // layer.msg('审批');
                layer.open({
                    content: "edit_list_match.html",
                    type: 2,
                    area: ["100%", "100%"],
                    title: "赛程安排",
                    shadeClose: true,
                    success: function (layero, index) {
                        //获取点击行的数据,获取打开的iframe
                        console.log(data.id)
                        var body = layer.getChildFrame('body', index);
                        var iframe = window['layui-layer-iframe' + index];
                        //调用子页面的全局函数
                        iframe.child(data.id)
                    }
                })
            };
            if (layEvent === "edit") {
                // layer.msg('审批');
                layer.open({
                    content: "choose_list_judge.html",
                    type: 2,
                    area: ["100%", "100%"],
                    title: "裁判安排",
                    shadeClose: true,
                    success: function (layero, index) {
                        //获取点击行的数据,获取打开的iframe
                        console.log(data.id)
                        var body = layer.getChildFrame('body', index);
                        var iframe = window['layui-layer-iframe' + index];
                        //调用子页面的全局函数
                        iframe.child(data.id)
                    }
                })
            };
            if (layEvent === 'approval') {
                layer.open({
                    content: "approvalNewcompetition.html",
                    type: 2,
                    area: ["600px", "250px"],
                    title: "赛事审批",
                    shadeClose: true,
                    success: function (layero, index) {
                        //获取点击行的数据,获取打开的iframe
                        console.log(data.id)
                        var body = layer.getChildFrame('body', index);
                        body.find('#id').attr("data-id", data.id); //填补ID
                    }
                })
            }
        });
    });
</script>